var directiveMod=angular.module("starter.directive", []);
directiveMod.directive('hideTabs',function($rootScope,$location){
  return {
    restrict:'AE',
    link:function($scope){
      $rootScope.hideTabs = 'tabs-item-hide';
      $scope.$on('$destroy',function(){
        //alert($location.path());
        if($location.path()=="/tab/home"||$location.path()=="/tab/setting"||$location.path()=="/tab/order"){
          $rootScope.hideTabs = '';
        }
      })
    }
  }
})
directiveMod.directive('hideHome',function($rootScope){
  return {
    restrict:'AE',
    link:function($scope){
      $rootScope.hideHome = 'hide';
      $scope.$on('$destroy',function(){
        //$rootScope.hideTabs = '';
      })
    }
  }
})
directiveMod.directive('compare', function () {
  {
    var o={};
    o.strict='AE';
    o.scope={
      orgText:'=compare'
    }
    o.require='ngModel';
    o.link= function (sco,ele,stt,con) {
      con.$validators.compare= function (v) {
        return v==sco.orgText;
      }
      sco.$watch('orgText', function () {
        con.$validate();
      })
    }
    return o;
  }
})

directiveMod.directive('fileModel', ['$parse', function ($parse) {
    return {
      restrict: 'A',
      link: function(scope, element, attrs, ngModel) {
        var model = $parse(attrs.fileModel);
        var modelSetter = model.assign;
        element.bind('change', function(event){
          scope.$apply(function(){
            modelSetter(scope, element[0].files[0]);
          });
          //附件预览
          scope.file = (event.srcElement || event.target).files[0];
          scope.getFile();
        });
      }
    };
  }]);
;




